<template>
    <el-form ref="form" :model="formData" label-width="40px">
      <el-form-item label="标题">
        <el-input v-model="formData.title"></el-input>
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="formData.data" type="textarea"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="createData">创建</el-button>
        <el-button @click="esc">取消</el-button>
      </el-form-item>
    </el-form>
  </template>

<script>
    import axios from 'axios'
    import message from '../modular/message.js'
    export default {
        data() {
            return {
                formData: {},
            }
        },
        methods: {
            createData() {
                axios.post('/article/create', this.formData).then(res => {
                    if (res.data.Code == 200) {
                        message(res.data.message, 'success')
                    } else {
                        message(res.data.message, 'error')
                    }
                    this.$router.push(`/article/list`)
                })
            },
            esc() {
                this.$router.push(`/article/list`)
            }
        },
    }
</script>